Package com.rnett.plugin.ir

The com.rnett.plugin.ir package contains a number of utilities for working with IR. This includes basic utilities such as CompilerConfiguration.messageCollector, IrClass.addAnonymousInitializer, IrType.raiseTo, and IrClass.typeWith(List<IrTypeArgument>), all of which are available as extension functions.

Many utilities require a IrPluginContext, so in lieu of multiple receivers, they are put in HasContext which has a val context: IrPluginContext. It can be easily implemented by IrElementTransformers. Of special note are the IrBuilderWithScope.buildLambda and lambdaArgument functions.

KnowsCurrentFile is a similar interface, but requires a IrFile and provides extensions for getting message locations from IrElements using said file.

Both of these are implemented by IrTransformer, which is usable as a replacement for IrElementTransformerVoid or IrElementTransformerVoidWithContext. In addition to implementing IrElementTransformerVoidWithContext , KnowsCurrentFile, and HasContext, it modifies the file transformer so that new declarations can be added to the current file without running into ConcurrentModificationException (it does so by running transforms on a copy of the declaration list, and then on newly added declarations until no more are added).

Types

FunctionRemapper
Link copied to clipboard
fun interface FunctionRemapper

Remap references to functions. Returning null will deep copy the symbol.

HasContext
Link copied to clipboard
interface HasContext

A bunch of things using context that should mostly be moved to multiple receivers

IrTransformer
Link copied to clipboard
abstract class IrTransformer(context: IrPluginContext, messageCollector: MessageCollector) : IrElementTransformerVoidWithContext, FileLoweringPass, HasContext, KnowsCurrentFile
IrTryBuilder
Link copied to clipboard
class IrTryBuilder(builder: IrBuilderWithScope)
KnowsCurrentFile
Link copied to clipboard
interface KnowsCurrentFile

Utility methods for working with a MessageCollector when the current file is available

ReferenceRemapper
Link copied to clipboard
interface ReferenceRemapper

A symbol remapper that only replaces references to symbols. Returning null will deep copy the symbol.

ReferenceReplacements
Link copied to clipboard
class ReferenceReplacements : ReferenceRemapper

A list of symbol replacements, providing a ReferenceRemapper.

ValueRemapper
Link copied to clipboard
fun interface ValueRemapper : ReferenceRemapper

Remap value symbols. If given a IrVariableSymbol, must return a IrVariableSymbol. Returning null will deep copy the symbol.

Functions

addAnonymousInitializer
Link copied to clipboard
inline fun IrClass.addAnonymousInitializer(builder: IrAnonymousInitializer.() -> Unit): IrAnonymousInitializer
buildStatement
Link copied to clipboard
inline fun <T : IrElement> IrGeneratorWithScope.buildStatement(startOffset: Int = UNDEFINED_OFFSET, endOffset: Int = UNDEFINED_OFFSET, origin: IrStatementOrigin? = null, builder: IrSingleStatementBuilder.() -> T): T
createIrBuilder
Link copied to clipboard
fun IrGeneratorContext.createIrBuilder(symbol: IrSymbol, startOffset: Int = UNDEFINED_OFFSET, endOffset: Int = UNDEFINED_OFFSET): DeclarationIrBuilder
deepCopyAndRemapFunctions
Link copied to clipboard
inline fun <T : IrElement> T.deepCopyAndRemapFunctions(initialParent: IrDeclarationParent? = null, referenceRemapper: FunctionRemapper): T

Deep copy and replace references to values.

deepCopyAndRemapReferences
Link copied to clipboard
inline fun <T : IrElement> T.deepCopyAndRemapReferences(initialParent: IrDeclarationParent? = null, referenceRemapper: ReferenceRemapper): T

Deep copy and replace references to symbols

inline fun <T : IrElement> T.deepCopyAndRemapReferences(initialParent: IrDeclarationParent? = null, referenceReplacements: ReferenceReplacements.Builder.() -> Unit): T

Deep copy and replace references

deepCopyAndRemapValues
Link copied to clipboard
inline fun <T : IrElement> T.deepCopyAndRemapValues(initialParent: IrDeclarationParent? = null, referenceRemapper: ValueRemapper): T

Deep copy and replace references to values

hasTypeArgument
Link copied to clipboard
fun IrType.hasTypeArgument(index: Int): Boolean
irJsExprBody
Link copied to clipboard
fun IrBuilderWithScope.irJsExprBody(expression: IrExpression, useExprOnJvm: Boolean = false): IrBody

IrExprBody on JS causes issues: (https://youtrack.jetbrains.com/issue/KT-49561).

irTry
Link copied to clipboard
fun IrBuilderWithScope.irTry(result: IrExpression, type: IrType = result.type): IrTry
inline fun IrBuilderWithScope.irTry(result: IrExpression, type: IrType = result.type, catches: IrTryBuilder.() -> Unit): IrTry
fun IrBuilderWithScope.irTry(result: IrExpression, type: IrType, catches: List<IrCatch>, finally: IrExpression? = null): IrTry
irTypeOf
Link copied to clipboard
inline fun <T> HasContext.irTypeOf(): IrType
inline fun <T> IrPluginContext.irTypeOf(): IrType
irVararg
Link copied to clipboard
fun IrBuilderWithScope.irVararg(elementType: IrType, elements: Iterable<IrExpression>): IrVararg
putTypeArguments
Link copied to clipboard
fun IrMemberAccessExpression<*>.putTypeArguments(vararg namedArgs: Pair<String, IrType?>, substitute: Boolean = this is IrCall)
fun IrMemberAccessExpression<*>.putTypeArguments(vararg args: IrType?, substitute: Boolean = this is IrCall)

Set the type arguments of the call. If substitute is true and this is an IrCall, calls substituteTypeParams.

putValueArguments
Link copied to clipboard
fun IrMemberAccessExpression<*>.putValueArguments(vararg namedArgs: Pair<String, IrExpression?>, substitute: Boolean = this is IrCall)
fun IrMemberAccessExpression<*>.putValueArguments(vararg args: IrExpression?, substitute: Boolean = this is IrCall)
raiseTo
Link copied to clipboard
inline fun IrType.raiseTo(predicate: (IrType) -> Boolean): IrType

Gets the lowest superclass or this that matches the predicate. Helpful for discovering the type parameters of supertypes.

fun IrType.raiseTo(classifier: IrClassifierSymbol): IrType

Gets the lowest superclass or this that has the given classifier. Helpful for discovering the type parameters of supertypes.

raiseToOrNull
Link copied to clipboard
inline fun IrType.raiseToOrNull(predicate: (IrType) -> Boolean): IrType?
fun IrType.raiseToOrNull(classifier: IrClassifierSymbol): IrType?

Gets the lowest superclass or this that matches the predicate, or null if none do. Helpful for discovering the type parameters of supertypes.

ReferenceReplacements
Link copied to clipboard
inline fun ReferenceReplacements(builder: ReferenceReplacements.Builder.() -> Unit): ReferenceReplacements

Build a list of symbol replacements

substituteTypeParams
Link copied to clipboard
fun IrCall.substituteTypeParams(): IrCall

Substitute the set type parameters into the return type.

supertypesWithSubstitution
Link copied to clipboard
fun IrType.supertypesWithSubstitution(): List<IrType>

Get the supertypes of a type, substituting type parameters for their values where known and not *.

typeArgument
Link copied to clipboard
fun IrType.typeArgument(index: Int): IrType
typeWith
Link copied to clipboard
fun IrClass.typeWith(arguments: List<IrTypeArgument>): IrSimpleType
fun IrClassifierSymbol.typeWith(arguments: List<IrTypeArgument>): IrSimpleType
valueArgumentsByName
Link copied to clipboard
fun IrCall.valueArgumentsByName(): Map<String, IrExpression?>

Get the arguments of an IrCall by their parameter names

withDispatchReceiver
Link copied to clipboard
fun <T : IrMemberAccessExpression<*>> T.withDispatchReceiver(receiver: IrExpression?, substitute: Boolean = this is IrCall): T
withExtensionReceiver
Link copied to clipboard
fun <T : IrMemberAccessExpression<*>> T.withExtensionReceiver(receiver: IrExpression?, substitute: Boolean = this is IrCall): T
withTypeArguments
Link copied to clipboard
fun <T : IrMemberAccessExpression<*>> T.withTypeArguments(vararg namedArgs: Pair<String, IrType?>, substitute: Boolean = this is IrCall): T
fun <T : IrMemberAccessExpression<*>> T.withTypeArguments(vararg args: IrType?, substitute: Boolean = this is IrCall): T

Set the type arguments of the call. If substitute is true and this is an IrCall, calls substituteTypeParams.

withValueArguments
Link copied to clipboard
fun <T : IrMemberAccessExpression<*>> T.withValueArguments(vararg namedArgs: Pair<String, IrExpression?>, substitute: Boolean = this is IrCall): T
fun <T : IrMemberAccessExpression<*>> T.withValueArguments(vararg args: IrExpression?, substitute: Boolean = this is IrCall): T

Properties

messageCollector
Link copied to clipboard
val CompilerConfiguration.messageCollector: MessageCollector
typeSystem
Link copied to clipboard
val IrGeneratorContextInterface.typeSystem: IrTypeSystemContext